package com.tanhua.server.controller;


import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVo;
import com.tanhua.server.server.QuestionService;
import com.tanhua.server.server.SettingsService;
import com.tanhua.server.server.UserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 通用设置相关
 */
@RestController
@RequestMapping("/users")
@Slf4j
public class SettingsController {
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private SettingsService settingsService;
    @Autowired
    private QuestionService questionService;


    /**
     *读取用户通用设置
     */
    @GetMapping("settings")
    public ResponseEntity settings(){
        SettingsVo settings = settingsService.settings();
        return ResponseEntity.ok(settings);
    }

    /**
     * 修改陌生人问题
     * @param map
     * @return
     */
    @PostMapping("questions")
    public ResponseEntity questions(@RequestBody Map map){
        String content = (String) map.get("content");
        settingsService.savequestions(content);
        return ResponseEntity.ok(null);
    }

    /**
     * 修改通用设置
     * @return
     */
    @PostMapping("notifications/setting")
    public ResponseEntity setting(@RequestBody Map map){
        settingsService.setting(map);
        return ResponseEntity.ok(null);
    }

    /**
     * 分页查询黑名单
     */
    @GetMapping("blacklist")
    public ResponseEntity blacklist(@RequestParam(defaultValue = "1") int page,
                                    @RequestParam(defaultValue = "10") int size){
        log.info("page={},sizi={}",page,size);
        PageResult pr = settingsService.blacklist(page,size);
         return ResponseEntity.ok(pr);
    }

    /**
     * 移除黑名单
     */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity delete(@PathVariable("uid") Long uid){
        settingsService.blacklistdelete(uid);
        return ResponseEntity.ok(null);
    }

    /**
     * 修改手机号发送的验证码
     * @return
     */
    @PostMapping("phone/sendVerificationCode")
    public ResponseEntity sendVerificationCod(){
        System.out.println("获得修改手机号发送的验证码");
        settingsService.sendVerificationCod();
        return ResponseEntity.ok(null);
    }

    /**
     * 校验验证码
     * @param map
     * @return
     */
    @PostMapping("/phone/checkVerificationCode")
    public ResponseEntity checkVerificationCode(@RequestBody Map map){
        //MultipartFile verificationCode = (MultipartFile) map.get("verificationCode");
        String verificationCode = (String) map.get("verificationCode");
        log.info("map={}",verificationCode);
        Map map1 = settingsService.checkVerificationCode(map);
        return ResponseEntity.ok(map1);
    }

    /**
     * 修改手机号
     * @param map
     * @return
     */
    @PostMapping("/phone")
    public ResponseEntity phone(@RequestBody Map map){
        String phone = (String) map.get("phone");
        log.info("map={}",phone);
        settingsService.phone(phone);
        return ResponseEntity.ok(null);
    }
}
